//
//  CarViolationPayViewController.m
//  EasyToo
//
//  Created by linshengqin on 13-9-3.
//
//

#import "CarViolationPayViewController.h"
#import "CarViolationManager.h"
#import "NetworkAlertView.h"
@interface CarViolationPayViewController ()

@end

@implementation CarViolationPayViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    carViolation_model = [CarViolationModel sharedata];
    [CarViolationManager shareManager].delegate = self;
    infoArray = [[NSArray alloc]initWithArray:(carViolation_model.violationInfoArray[0])];
	// Do any additional setup after loading the view.
    [self initMainView];
    [self initDetailView];
   
}

-(void)initMainView
{
    _bgScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [DeviceUtil getScreenWidth], [DeviceUtil getScreenHeight])];
    [self.view addSubview:_bgScrollView];
    _bgScrollView.contentSize = CGSizeMake(320, 700);
    _bgScrollView.showsVerticalScrollIndicator = YES;
    
}

-(void)initDetailView
{
    UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 340)];
    imageView.image = [UIImage imageNamed: @"list2" ];
    //    UIImageView *imageView = [[UIImageView alloc] initWithImage:image] ;
    [_bgScrollView addSubview:imageView];
    
    //[self.view setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @"qq_list"]]];
    // Do any additional setup after loading the view.
    UILabel *label_message = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 150, 30)];
    label_message.text = @"违章信息";
    label_message.textColor = [UIColor redColor];
    label_message.font = [UIFont systemFontOfSize:20];
    label_message.backgroundColor = [UIColor clearColor];
    [_bgScrollView addSubview:label_message];
    
    int i = 50;
    
    UILabel *label_account = [[UILabel alloc] initWithFrame:CGRectMake(30, i, 250, 20)];
    label_account.font = [UIFont systemFontOfSize:13];
    [label_account setText:[NSString stringWithFormat:@"车牌号 :%@",carViolation_model.vehicleNo]];
    [_bgScrollView addSubview:label_account];
    
    
    UILabel *label_price = [[UILabel alloc] initWithFrame:CGRectMake(30, i+30, 250, 20)];
    label_price.font = [UIFont systemFontOfSize:13];
    [label_price setText:[NSString stringWithFormat:@"办理违章笔数 : %d笔",[carViolation_model.violationInfoArray count]]];
    [_bgScrollView addSubview:label_price];
    
    UILabel *label_pay = [[UILabel alloc] initWithFrame:CGRectMake(30, i+60, 250, 20)];
    label_pay.font = [UIFont systemFontOfSize:13];
    [label_pay setText:[NSString stringWithFormat:@"业务本金 :%d元 ",[infoArray[6] intValue]/100]];
    //label_pay.text = @"支付方式:%@", self.payType;
    [_bgScrollView addSubview:label_pay];
    
    UILabel *label_pay1 = [[UILabel alloc] initWithFrame:CGRectMake(30, i+90, 250, 20)];
    label_pay1.font = [UIFont systemFontOfSize:13];
    [label_pay1 setText:[NSString stringWithFormat:@"滞纳金 : %d元",[infoArray[7] intValue]/100]];
    //label_pay.text = @"支付方式:%@", self.payType;
    [_bgScrollView addSubview:label_pay1];
    
    UILabel *label_pay2 = [[UILabel alloc] initWithFrame:CGRectMake(30, i+130, 250, 20)];
    label_pay2.font = [UIFont systemFontOfSize:13];
    [label_pay2 setText:[NSString stringWithFormat:@"服务费 : %d元",[infoArray[8] intValue]/100]];
    //label_pay.text = @"支付方式:%@", self.payType;
    [_bgScrollView addSubview:label_pay2];
    
    UILabel *label_pay3 = [[UILabel alloc] initWithFrame:CGRectMake(30, i+160, 250, 20)];
    label_pay3.font = [UIFont systemFontOfSize:13];
    if ([carViolation_model.postMode intValue]==1)
    {
        [label_pay3 setText:[NSString stringWithFormat:@"快递费用 : %d元",[carViolation_model.postFee intValue]/100]];
    }
    else
    {
        label_pay3.text = @"0元";
    }
    //label_pay.text = @"支付方式:%@", self.payType;
    [_bgScrollView addSubview:label_pay3];
    
    UILabel *label_pay4 = [[UILabel alloc] initWithFrame:CGRectMake(30, i+190, 250, 20)];
    label_pay4.font = [UIFont systemFontOfSize:13];
    [label_pay4 setText:[NSString stringWithFormat:@"联系电话 : %@",carViolation_model.phoneNum]];
    //label_pay.text = @"支付方式:%@", self.payType;
    [_bgScrollView addSubview:label_pay4];
    
    UILabel *label_pay5 = [[UILabel alloc] initWithFrame:CGRectMake(30, i+220, 250, 20)];
    label_pay5.font = [UIFont systemFontOfSize:13];
    [label_pay5 setText:[NSString stringWithFormat:@"支付方式 : 银联"]];
    //label_pay.text = @"支付方式:%@", self.payType;
    [_bgScrollView addSubview:label_pay5];
    
    
    UILabel *label_total = [[UILabel alloc] initWithFrame:CGRectMake(200, i+250, 100, 20)];
    [label_total setText:[NSString stringWithFormat:@"合计 : %@元",carViolation_model.totalAmount]];
    label_total.textColor = [UIColor redColor];
    label_total.font = [UIFont systemFontOfSize:18];
    label_total.backgroundColor = [UIColor clearColor];
    [_bgScrollView addSubview:label_total];
    
    UIButton *confirmButton = [[UIButton alloc] initWithFrame:CGRectMake(40, 340, 230, 40)];
    [confirmButton setBackgroundImage:[UIImage imageNamed:@"button_3"] forState:UIControlStateNormal];
    [confirmButton setTitle:@"确认支付" forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(confirmPay:) forControlEvents:UIControlEventTouchUpInside];
    [_bgScrollView addSubview:confirmButton];
}

-(void)confirmPay:(id)sender
{
    /*
    UIAlertView *av= [[UIAlertView alloc] initWithTitle:@"提示" message:@"未登陆,请先登陆或注册" delegate:self  cancelButtonTitle:@"注册" otherButtonTitles:@"登陆", nil];
    [av show];
    [av release];
     */
    int total = [infoArray[6] intValue]+[infoArray[7] intValue]+[infoArray[8] intValue];
    carViolation_model.totalAmount = [NSString stringWithFormat:@"%d",total];
    [[CarViolationManager shareManager] orderViolation:carViolation_model.vehicleNo VehicleColor:carViolation_model.colorType RackNo:carViolation_model.rackNo EnginNo:carViolation_model.enginNo PostMode:carViolation_model.postMode PostFee:carViolation_model.postFee PhoneNum:carViolation_model.phoneNum OrderDetail:carViolation_model.orderDetail TotalAmount:carViolation_model.totalAmount];
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)onOrderViolationFinish:(BOOL)isSuccess Tn:(NSString *)tn
{
    [[NetworkAlertView shareView] delView];
    
    [UPPayPlugin startPay:tn sysProvide:nil spId:nil mode:PAY_MODE_REALEASE viewController:self delegate:self];
}

-(void)UPPayPluginResult:(NSString*)result
{
    NSString *alertString = nil;
    if ([result isEqualToString:@"success"])
    {
        alertString = @"交易成功";
    }
    else if ([result isEqualToString:@"cancel"])
    {
        alertString = @"交易取消";
    }
    else
    {
        alertString = @"交易失败";
    }
    
    UIAlertView *alert = [[UIAlertView alloc]  initWithTitle:@"支付结果" message:alertString  delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alert show];
    
}

@end
